const { contextBridge,ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('versions', {
    node: () => process.versions.node,
    chrome: () => process.versions.chrome,
    electron: () => process.versions.electron,
    // we can also expose variables, not just functions
})

contextBridge.exposeInMainWorld('t1', {

})

contextBridge.exposeInMainWorld('electronAPI', {

    //同步调用主进程-渲染进程需要等待主进程返回结果
    runExecSync: (cmdStr) => ipcRenderer.invoke('runExecSync',cmdStr),

    //异步调用主进程-渲染进程不需要等待主进程返回结果,需额外添加监听器监听事件
    runExec: (cmdStr) => ipcRenderer.invoke('runExec', cmdStr),
    //监听器监听事件
    onListenMainCmdMsg: (callback) => ipcRenderer.on('onListenMainCmdMsg', callback),
    //单向调用主进程-只需要执行,不用返回结果,目前方法名起的随意,后边改
    stopCmdExecution: (flag) => ipcRenderer.send('stopCmdExecution', flag),


    openFileDialog: () => ipcRenderer.invoke('openFileDialog'),

    //ssh2-远程连接主机
    connectToRemoteHost: (cmdStr,atOnce) => ipcRenderer.invoke('connectToRemoteHost',cmdStr,atOnce),
    //监听器监听ssh事件输出
    onListenMainRemoteMsg: (callback) => ipcRenderer.on('onListenMainRemoteMsg', callback),
    //停止正在执行的ssh事件输出
    stopOnListenMainRemoteStream: () => ipcRenderer.invoke('stopOnListenMainRemoteStream'),

    //停止正在执行的ssh事件输出
    test: () => ipcRenderer.invoke('test'),
})